<style >
  .el-checkbox{line-height: 24px;}
  .changeSize .el-dialog.el-dialog--small{
    width:76%!important;
  }
  .el-dialog__wrapper .el-form--inline .el-form-item__label{
    text-align: left;
  }
</style>
<template>
  <div>
    <el-form :inline="true"  class="demo-form-inline" :model="formInline">
      <!-- ASN编号-->
      <el-form-item :label="nowLangue.sanCode" class="selectMB10">
        <el-input size="mini" :placeholder="nowLangue.pleaseImport+nowLangue.sanCode" v-model="formInline.asnCode"></el-input>

      </el-form-item>
      <!-- PO编号-->
      <el-form-item :label="nowLangue.poCode" class="selectMB10">
        <el-input size="mini" :placeholder="nowLangue.pleaseImport+nowLangue.poCode" v-model="formInline.orderCode"></el-input>
      </el-form-item>
      <!-- 订单类型-->
      <el-form-item :label="nowLangue.orderType" class="selectMB10">
        <el-select size="mini"  clearable  :placeholder="nowLangue.pleaseSelect+nowLangue.orderType"  v-model="formInline.orderType">
          <el-option v-for="(sourceMode,index) in sourceModeData" :key="index" :label="sourceMode.label" :value="sourceMode.value"></el-option>
        </el-select>
      </el-form-item>
      <!--条码类别-->
      <el-form-item :label="nowLangue.barCodeType" class="selectMB10">
        <el-select size="mini"  clearable  :placeholder="nowLangue.pleaseSelect+nowLangue.barCodeType" v-model="formInline.dataType">
          <el-option v-for="(barCodeType,index) in barCodeTypeData" :key="index" :label="barCodeType.label" :value="barCodeType.value"></el-option>
        </el-select>
      </el-form-item>
      <!--条码打印地-->
      <el-form-item :label="nowLangue.barCodeArea" class="selectMB10">
        <el-select size="mini"  clearable  :placeholder="nowLangue.pleaseSelect+nowLangue.barCodeArea" v-model="formInline.snCodeSource">
          <el-option v-for="(codeSource,index) in codeSourceData" :key="index" :label="codeSource.label" :value="codeSource.value"></el-option>
        </el-select>
      </el-form-item>
      <!-- 供应商编号-->
      <el-form-item :label="nowLangue.supplierNumber" class="selectMB10">
        <el-input size="mini" :placeholder="nowLangue.pleaseImport+nowLangue.supplierNumber" v-model="formInline.supplierCode"></el-input>
      </el-form-item>
      <!-- 供应商名称-->
      <el-form-item :label="nowLangue.supplierName" class="selectMB10">
        <el-input size="mini" :placeholder="nowLangue.pleaseImport+nowLangue.supplierName" v-model="formInline.supplierName"></el-input>
      </el-form-item>
      <!-- 备件编码-->
      <el-form-item :label="nowLangue.spareCode" class="selectMB10" v-if="show">
        <el-input size="mini" :placeholder="nowLangue.pleaseImport+nowLangue.spareCode" v-model="formInline.materialCode"></el-input>
      </el-form-item>
      <!-- 备件名称-->
      <el-form-item :label="nowLangue.spareName" class="selectMB10" v-if="show">
        <el-input size="mini" :placeholder="nowLangue.pleaseImport+nowLangue.spareName" v-model="formInline.materialName"></el-input>
      </el-form-item>
      <!-- 生成时间-->
      <el-form-item :label="nowLangue.createTime" class="selectMB10" v-if="show">
        <el-date-picker size="mini" type="date" :placeholder="nowLangue.pleaseSelect" v-model="formInline.startCreateTime" @change="startTime"></el-date-picker>
        <span  class="mlr10" v-text="nowLangue.to"></span>
        <el-date-picker size="mini" type="date" :placeholder="nowLangue.pleaseSelect" v-model="formInline.endCreateTime" @change="endTime"></el-date-picker>
      </el-form-item>
      <!-- 联想技服条码-->
      <el-form-item :label="nowLangue.lenovoBarcode" class="selectMB10" v-if="show">
        <el-input size="mini" :placeholder="nowLangue.pleaseImport+nowLangue.lenovoBarcode" v-model="formInline.snCode"></el-input>
      </el-form-item>
      <!-- 供应商条码-->
      <el-form-item :label="nowLangue.vendorBarcode" class="selectMB10" v-if="show">
        <el-input size="mini" :placeholder="nowLangue.pleaseImport+nowLangue.vendorBarcode" v-model="formInline.supplierSn"></el-input>
      </el-form-item>
      <!-- 操作人-->
      <el-form-item :label="nowLangue.operator" class="selectMB10" v-if="show">
        <el-input size="mini" :placeholder="nowLangue.pleaseImport+nowLangue.operator" v-model="formInline.personName"></el-input>
      </el-form-item>
      <el-form-item class="selectMB10">
        <el-button class="bolder outsideBtnBS"  size="mini" type="danger"  @click="show=!show" v-if="!show" v-text="nowLangue.more"></el-button>
        <el-button class="bolder outsideBtnBS"  size="mini" type="danger"  @click="show=!show" v-if="show" v-text="nowLangue.packUp"></el-button>
        <el-button class="bolder outsideBtnBS"  size="mini" type="danger" :disabled="selectDisabled" v-text="nowLangue.query" @click="query" ></el-button>
      </el-form-item>
    </el-form>
    <div>
      <label class="default-label " v-text="nowLangue.spareCodeList"></label>
      <el-button class="bolder outsideBtnBS" size="mini" type="danger"  @click="nextPrint" :disabled="!radio" v-text="nowLangue.nextPrint"></el-button>
    </div>
    <el-table  border style="width: 100%;" v-loading.body="loading" element-loading-text="拼命加载中" :data="codeLists">
      <el-table-column  type="index" header-align="center" align="center" :label="nowLangue.sequence" width="40" show-overflow-tooltip></el-table-column>
      <el-table-column  header-align="center" align="center" :label="nowLangue.operate">
          <template scope="scope">
            <el-radio v-model="radio" :label="scope.row.id" size="mini">&nbsp;</el-radio>
          </template>
      </el-table-column>
      <!--备件编码-->
      <el-table-column prop="materialCode" header-align="center" align="center" :label="nowLangue.spareCode  " show-overflow-tooltip></el-table-column>
      <!--备件名称-->
      <el-table-column prop="materialName" header-align="center" align="center" :label="nowLangue.spareName " show-overflow-tooltip></el-table-column>
      <!--联想技服条码-->
      <el-table-column prop="snCode" header-align="center" align="center" :label="nowLangue.lenovoBarcode " show-overflow-tooltip></el-table-column>
      <!--SN（或商-->
      <el-table-column prop="supplierSn" header-align="center" align="center" :label="nowLangue.snBarCode" show-overflow-tooltip></el-table-column>
      <!--供应商编码-->
      <el-table-column prop="supplierCode" header-align="center" align="center" :label="nowLangue.supplierCode" show-overflow-tooltip></el-table-column>
      <!--供应商名称-->
      <el-table-column prop="supplierName" header-align="center" align="center" :label="nowLangue.supplierName" show-overflow-tooltip></el-table-column>
      <!--条码打印地-->
      <el-table-column prop="snCodeSourceName" header-align="center" align="center" :label="nowLangue.barCodeArea" show-overflow-tooltip></el-table-column>
      <!--生成时间-->
      <el-table-column prop="createTime" header-align="center" align="center" :label="nowLangue.createTime" show-overflow-tooltip></el-table-column>
      <!--订单类型-->
      <el-table-column prop="orderTypeName" header-align="center" align="center" :label="nowLangue.orderType" show-overflow-tooltip></el-table-column>
      <!--订单编号-->
      <el-table-column prop="orderCode" header-align="center" align="center" :label="nowLangue.orderNumber" show-overflow-tooltip></el-table-column>
      <!--ASN编号-->
      <el-table-column prop="asnCode" header-align="center" align="center" :label="nowLangue.sanCode" show-overflow-tooltip></el-table-column>
      <!--收货单编号-->
      <el-table-column prop="receiptNo" header-align="center" align="center" :label="nowLangue.invoiceNumber" show-overflow-tooltip></el-table-column>
    </el-table>
    <el-pagination v-if="isPaging"  @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="currentPage3" :current-page="pageIndex"  :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :page-count="totalPage" :total="totalNumber"></el-pagination>
    <el-dialog :title="nowLangue.nextPrintTitle " :visible.sync="dialogUpdate" size="small" class="changeSize" :lock-scroll="false" >
      <el-form :inline="true"  ref="updateForm" :model="updateForm" class="label-minW95">
        <!-- 备件编码-->
        <el-form-item :label="nowLangue.spareCode  " class="selectMB10">
          <el-input size="mini" disabled v-model="updateForm.materialCode"></el-input>
        </el-form-item>
        <!-- 备件名称-->
        <el-form-item :label="nowLangue.spareName" class="selectMB10">
          <el-input size="mini"  disabled v-model="updateForm.materialName"></el-input>
        </el-form-item>
        <!-- 本次生成数量-->
        <el-form-item :label="nowLangue.generatedNum" class="selectMB10">
          <el-input size="mini" value="1" disabled></el-input>
        </el-form-item>
        <!-- 条码类别-->
        <el-form-item :label="nowLangue.barCodeType" class="selectMB10">
          <el-input size="mini" disabled v-model="updateForm.snCategory"></el-input>
        </el-form-item>
        <!-- 区别码1-->
        <el-form-item :label="nowLangue.diffCode1" class="selectMB10">
          <el-input size="mini" disabled  v-model="updateForm.diffCode1"></el-input>
        </el-form-item>
        <!-- 区别码2-->
        <el-form-item :label="nowLangue.diffCode2" class="selectMB10">
          <el-input size="mini" disabled v-model="updateForm.diffCode2"></el-input>
        </el-form-item>
        <!-- 打印区别码-->
        <el-form-item  class="selectMB10">
          <el-checkbox  v-model="updateForm.diffFlag"   v-cloak>{{nowLangue.printDiffCode}}</el-checkbox>
        </el-form-item>
        <!-- 条码打印地-->
        <el-form-item  class="selectMB10" :label="nowLangue.barCodeArea ">
          <el-input size="mini" disabled v-model="updateForm.snCodeSourceName"></el-input>
        </el-form-item>
        <!-- 来源地区-->
        <el-form-item  class="selectMB10" :label="nowLangue.sourceArea">
          <el-input size="mini" disabled v-model="updateForm.sourceRegionName"></el-input>
        </el-form-item>
        <!-- 来源方式-->
        <el-form-item  class="selectMB10" :label="nowLangue.sourceMode">
          <el-input size="mini" disabled v-model="updateForm.sourceModeName"></el-input>
        </el-form-item>
        <!-- 联想技服条码-->
        <el-form-item  class="selectMB10" :label="nowLangue.lenovoBarcode">
          <el-input size="mini" disabled v-model="updateForm.snCode"></el-input>
        </el-form-item>
        <!-- 供应商条码-->
        <el-form-item  class="selectMB10" :label="nowLangue.vendorBarcode">
          <el-input size="mini" disabled  v-model="updateForm.supplierSn"></el-input>
        </el-form-item>
        <div>
          <!--打印方式-->
          <el-form-item  class="selectMB10" :label="nowLangue.printType" prop="printMode" :rules="[{ required: true, message: nowLangue.pleaseSelect}]">
            <el-select size="mini"  :placeholder="nowLangue.pleaseSelect" v-model="updateForm.printMode">
              <el-option v-for="(printMode,index) in printModeData" :key="index" :label="printMode.label" :value="printMode.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item  class="selectMB10">
            <el-checkbox v-model="updateForm.lenovoFlag" v-cloak>{{nowLangue.printSign}}</el-checkbox>
          </el-form-item>
          <!--选择打印机-->
          <el-form-item  class="selectMB10" :label="nowLangue.selectPrinter" prop="printerType" :rules="[{ required: true, message: nowLangue.pleaseSelect}]">
            <el-select size="mini" :placeholder="nowLangue.pleaseSelect"  v-model="updateForm.printerType" @change="changeType">
              <el-option v-for="(printer,index) in available_printers" :key="index" :label="printer.name":value="printer.uid"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item  class="selectMB10">
            <el-button class="bolder outsideBtnBS selectAll"  size="mini" type="danger" :disabled="printDisabled" v-text="nowLangue.print" @click="printSure"></el-button>
            <el-button class="bolder outsideBtnBS selectAll"  size="mini" type="danger" @click="backPrint" v-text="nowLangue.back"></el-button>
          </el-form-item>
        </div>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
  export default {
      data() {
          return {
              radio: "",
              nowLangue: {},
              language: {
                  zh: {
                      "sanCode": "ASN编号",
                      "poCode": "PO编号",
                      "pleaseSelect": "请选择",
                      "pleaseImport": "请输入",
                      "orderType": "订单类型",
                      "barCodeType": "条码类别",
                      "barCodeArea": "条码打印地",
                      "supplierNumber": "供应商编号",
                      "supplierName": "供应商名称",
                      "spareCode": "备件编码",
                      "spareName": "备件名称",
                      "createTime": "生成时间",
                      "lenovoBarcode": "联想技服条码",
                      "vendorBarcode": "供应商条码",
                      "operator": "操作人",
                      "more": "更多",
                      "packUp": "收起",
                      "query": "查询",
                      "spareCodeList": "备件条码明细列表",
                      "nextPrint": "再次打印",
                      "operate": "操作",
                      "supplierCode": "供应商编码",
                      "orderNumber": "订单编号",
                      "invoiceNumber": "收货单编号",
                      "snBarCode": "SN（或商品条码）",
                      "sequence": "序",
                      "printType": "打印方式",
                      "sourceArea": "来源地区",
                      "sourceMode": "来源方式",
                      "selectPrinter": "选择打印机",
                      "printSign": "打印Lonovo标记",
                      "nextPrintTitle": "再次打印条码",
                      "printDiffCode": "打印区别码",
                      "generatedNum": "本次生成数量",
                      "diffCode1": "区别码1",
                      "diffCode2": "区别码2",
                      "to": "至",
                      "print": "打印",
                      "back": "返回",
                  },
                  en: {
                      "sanCode": "ASN Code",
                      "poCode": "PO Code",
                      "pleaseSelect": "please Select",
                      "pleaseImport": "please Import",
                      "orderType": "order Type",
                      "barCodeType": "bar Code Type",
                      "barCodeArea": "bar Code Area",
                      "supplierNumber": "supplier Number",
                      "supplierName": "supplier Name",
                      "spareCode": "spare Code",
                      "spareName": "spare Name",
                      "createTime": "create Time",
                      "lenovoBarcode": "lenovo Barcode",
                      "vendorBarcode": "vendor Barcode",
                      "operator": "operator",
                      "more": "more",
                      "packUp": "pack Up",
                      "query": "query",
                      "spareCodeList": "spare Code List",
                      "nextPrint": "next Print",
                      "operate": "operate",
                      "supplierCode": "supplier Code",
                      "orderNumber": "order Number",
                      "invoiceNumber": "invoice Number",
                      "snBarCode": "SN Bar Code",
                      "sequence": "sequence",
                      "printType": "print Type",
                      "sourceArea": "source Area",
                      "sourceMode": "source Mode",
                      "selectPrinter": "select Printer",
                      "printSign": "print Lonovo Sign",
                      "nextPrintTitle": "next Print Title",
                      "printDiffCode": "print Diff Code",
                      "generatedNum": "generated Num",
                      "diffCode1": "diff Code 1",
                      "diffCode2": "diff Code 2",
                      "to": "to",
                      "print": "print",
                      "back": "back"

                  }
              },
              formInline: {
                  asnCode: "",//ASN编号
                  orderCode: "",//订单编号
                  orderType: "",//订单类型
                  supplierCode: "",//供应商编码
                  supplierName: "",//供应商名称
                  materialCode: "",//备件编码
                  materialName: "",//备件名称
                  dataType: "1",//条码类别
                  snCodeSource: "",//条码打印地
                  startCreateTime: "",//生成时间开始
                  endCreateTime: "",//生成时间截止
                  personName: "",//操作人
                  snCode: "",//技服条码
                  supplierSn: "",//供应商条码
              },
              codeLists: [],
              snTypeData:[],//条码类型
              barCodeTypeData:[],
              diffCode1Data:[],//区别码1
              diffCode2Data:[],//区别码2
              codeSourceData:[],//条码打印地
              sourceRegionData:[],//来源地区
              sourceModeData:[],//来源方式
              printModeData:[],//打印方式
              printerTypeData:[],//选择打印机
              updateForm: {
                  printQuantity:1,
                  snCode: "",//技服条码
                  supplierSn: "",//供应商条码（可能为空值）
                  printerType: "",//选择打印机
                  diffFlag: false,//打印区别码（1是0否）
                  lenovoFlag: true,//打印Lenovo标记（1是0否）
                  printMode: ""//打印方式
              },
              show: false,//更多和收起控制
              flagPrint: false,//再次打印按钮显示还是不显示
              dialogUpdate: false,
              printParmData:[],//打印决定参数
              loading: false,
              isPaging: false,    //是否显示分页
              pageIndex: 1,    //当前页（必传）
              pageSize: 10,   //每页多少条
              currentPage: 1,    //当前显示3页
              currentPage3: 3,
              totalNumber: 1,     //总条数
              totalPage: 1,    //总页数
              //按钮禁用
              selectDisabled:false,
              printDisabled:false,
              //打印
              printObj:new Zebra(),//创建一个打印对象
              selected_printer: null,//选中得打印机
              default_mode: true,
              available_printers: null,//所有打印机
              selected_category: null,
              default_printer: null,//默认打印机
              format_start: "^XA ",
              format_end: "^XZ",
              format_content:"",
              isPrintMode4Flag:false,//打印三包装时，打印第二次外包装的判断
          };
      },
      created: function () {
          var _this = this;
          _this.languageType == "zh" ? _this.nowLangue = _this.language.zh : _this.nowLangue = _this.language.en;
      },
      computed: {
          languageType(){
              return this.$store.state.languageType;
          }
      },
      watch: {
          languageType(){
              var _this = this;
              _this.languageType == "zh" ? _this.nowLangue = _this.language.zh : _this.nowLangue = _this.language.en;
          }
      },
      mounted: function () {
          this.queryDropDownCommon()
          this.query();
          this.setup_web_print();//打印初始化
      },
      methods: {
          setup_web_print(){
              var _this=this;
              this.default_mode = true;
              this.selected_printer = null;
              this.available_printers = null;
              this.selected_category = null;
              this.default_printer = null;
              BrowserPrint.getDefaultDevice('printer', function(printer) {
                      _this.default_printer = printer;
                      if((printer != null) && (printer.connection != undefined)) {
                          _this.selected_printer = printer;
                      }
                      BrowserPrint.getLocalDevices(function(printers) {
                          _this.available_printers = printers;
                          if(_this.available_printers) {
                              if (_this.available_printers.length == 1) {
                                  //当打印机只有一个时，直接显示
                                  _this.updateForm.printerType = _this.available_printers[0].uid;
                              }
                          }
                          var printers_available = false;
                          if (printers != undefined) {
                              for(var i = 0; i < printers.length; i++) {
                                  if (printers[i].connection == 'usb') {
                                      printers_available = true;
                                  }
                              }
                          }
                          if(!printers_available) {
                              _this.common.errorTip("No Zebra Printers could be found!");
                              return;
                          }
                          else if(_this.selected_printer == null) {
                              _this.default_mode = false;
                          }
                      }, undefined, 'printer');
                  },
                  function(error_response) {
                      _this.common.errorTip("An error occured while attempting to connect to your Zebra Printer. You may not have Zebra Browser Print installed, or it may not be running. Install Zebra Browser Print, or start the Zebra Browser Print Service, and try again.");
                  });
          },
          //所有得下拉框
          queryDropDownCommon(){
              var _this = this;
              var tmp = [
                  "sn.barCodeType",
                  "sn.sourceMode",
                  "sn.snType",
                  "sn.diffCode1",
                  "sn.diffCode2",
                  "sn.codeSource",
                  "sn.sourceRegion",
                  "sn.sourceMode",
                  "sn.printMode",
                  "sn.printerType"
              ];
              $.ajax({
                  type: 'POST',
                  url: _this.metadata_service + 'metadata/getPullDownList',
                  cache:false,
                  data:JSON.stringify(tmp),
                  dataType:'JSON',
                  contentType:"application/json;charset=utf-8",
                  success: function (data) {
                      if (data.success) {
                          _this.barCodeTypeData=data.data['sn.barCodeType'];//条码类别
                          _this.sourceModeData=data.data['sn.sourceMode'];//订单类型(同来源方式取值相同)
                          _this.snTypeData=data.data['sn.snType'];//条码类型
                          _this.diffCode1Data=data.data['sn.diffCode1'];//区别码1
                          _this.diffCode2Data=data.data['sn.diffCode2'];//区别码2
                          _this.codeSourceData=data.data['sn.codeSource'];//条码打印地
                          _this.sourceRegionData=data.data['sn.sourceRegion'];//来源地区
                          _this.sourceModeData=data.data['sn.sourceMode'];//来源方式
                          _this.printModeData=data.data['sn.printMode'];//打印方式
                          _this.printerTypeData=data.data['sn.printerType'];//选择打印机
                      } else {
                          _this.common.errorTip(data.errorMessage);
                      }
                  }
              })
          },
          query(){
              var _this = this;
              _this.loading = true;
              _this.selectDisabled=true;
              var tmp = JSON.parse(JSON.stringify(_this.formInline));
              tmp.pageSize = _this.pageSize;
              tmp.pageIndex = _this.pageIndex;
              $.ajax({
                  type: 'POST',
                  url: _this.metadata_service + "barCode/querySNPage",
                  cache:false,
                  data:JSON.stringify(tmp),
                  dataType:'JSON',
                  contentType:"application/json;charset=utf-8",
                  success: function (data) {
                      _this.selectDisabled=false;
                      _this.loading = false;
                      if (data.success) {
                          _this.isPaging = true;
                          _this.codeLists = data.data.dataList;
                          _this.totalNumber = data.data.totalNumber;    //总条数
                          _this.totalPage = data.totalPage;    //总页数
                      } else{
                          _this.isPaging = false;
                          _this.common.errorTip(data.errorMessage);
                      }
                  },
                  error:function(){
                      _this.selectDisabled=false;
                      _this.loading = false;
                  }
              });
          },
          nextPrint(){
              var obj;
              for(var i=0;i<this.codeLists.length;i++){
                  if(this.codeLists[i].id==this.radio){
                      obj=this.codeLists[i]
                  }
              }
              for(var i in obj){
                  this.updateForm[i]=obj[i];
              }
              this.dialogUpdate = true;
          },
          //选择打印机
          changeType(){
              for(var i=0;i<this.available_printers.length;i++){
                  if(this.available_printers[i].uid==this.updateForm.printerType){
                      this.selected_printer=this.available_printers[i];
                  }
              }
          },
          //判断一个字符串中字母得数量
        /*  haveLetterNum(str){
            var letterNum=0;
            for(var i=0;i<str.length;i++){
                if(str.charCodeAt(i)>=65 && str.charCodeAt(i)<=90){
                    letterNum++;
                }
            }
            return letterNum
          },*/
          printSure(){
              var _this = this;
              this.$refs['updateForm'].validate((valid) => {
                  if (valid) {
                      _this.printDisabled=true;
                     var tmp=JSON.parse(JSON.stringify(_this.updateForm));
                      $.ajax({
                          type: 'POST',
                          url: _this.metadata_service + "barCode/rePrintSN",
                          cache: false,
                          data: JSON.stringify(tmp),
                          dataType: 'JSON',
                          contentType: "application/json;charset=utf-8",     //*****
                          success: function (data) {
                              _this.printDisabled=false;
                              if (data.success) {
                                //调用打印
                                  _this.printObj.barCode=_this.updateForm.snCode;
                                  _this.printObj.lenovoFlag = _this.updateForm.lenovoFlag;//打印lenovo标记
                                  _this.printObj.diffFlag = _this.updateForm.diffFlag;//打印区别码标记
                                  _this.printObj.diffCon = _this.updateForm.diffCode1;//区别码内容
                                  //内包装     //双包装     三包装,两个外包装一个内包装
                                  if (_this.updateForm.printMode == "1" || _this.updateForm.printMode == "3" || _this.updateForm.printMode == "4" ) {
                                      _this.printInner();
                                  }
                                  //外包装
                                  else if (_this.updateForm.printMode == "2") {
                                      _this.printOuter();
                                  }
                              } else
                                  _this.common.errorTip(data.errorMessage);
                          },
                          error:function(){
                              _this.printDisabled=false;
                          }
                      });
                  } else {
                      var err = _this.languageType == "zh" ? '存在未填写的必填项！' : 'Have Empty';
                      _this.common.errorTip(err);
                  }
              })
          },
          checkPrinterStatus(finishedFunction){
              var _this=this;
              _this.selected_printer.sendThenRead("~HQES",
                  function(text){
                      var that = this;
                      var statuses = new Array();
                      var ok = false;
                      var is_error = text.charAt(70);
                      var media = text.charAt(88);
                      var head = text.charAt(87);
                      var pause = text.charAt(84);
                      // check each flag that prevents printing
                      if (is_error == '0')
                      {
                          ok = true;
                          statuses.push("Ready to Print");
                      }
                      if (media == '1')
                          statuses.push("Paper out");
                      if (media == '2')
                          statuses.push("Ribbon Out");
                      if (media == '4')
                          statuses.push("Media Door Open");
                      if (media == '8')
                          statuses.push("Cutter Fault");
                      if (head == '1')
                          statuses.push("Printhead Overheating");
                      if (head == '2')
                          statuses.push("Motor Overheating");
                      if (head == '4')
                          statuses.push("Printhead Fault");
                      if (head == '8')
                          statuses.push("Incorrect Printhead");
                      if (pause == '1')
                          statuses.push("Printer Paused");
                      if ((!ok) && (statuses.Count == 0))
                          statuses.push("Error: Unknown Error");
                      finishedFunction(statuses.join());
                  }, _this.printerError);
          },
          printerError(text){
              this.common.errorTip("An error occurred while printing. Please try again." + text);
          },
          printInner(){
              var _this=this;
              this.printObj.printMode = "1";//打印内外包装码 1内包装 2外包装
              this.printObj.toZPL();//获取ZPL语言
              this.format_content=this.printObj.format_content;
              this.checkPrinterStatus( function (text){
                  if (text == "Ready to Print") {
                      _this.selected_printer.send(_this.format_start + _this.format_content + _this.format_end, function(){
                          _this.common.successTip("Print Inner Success");
                          if(_this.updateForm.printMode == "3" || _this.updateForm.printMode == "4"){
                              _this.isPrintMode4Flag=true;
                              _this.printOuter();
                          }
                      }, function(){
                          _this.common.errorTip("Print Inner Error")
                      });
                  }
                  else {
                      _this.common.errorTip("errorInner");
                  }
              });
          },
          printOuter(){
              var _this=this;
              this.printObj.printMode = "2";//打印内外包装码 1内包装 2外包装
              this.printObj.toZPL();//获取ZPL语言
              this.format_content=this.printObj.format_content;
              this.checkPrinterStatus( function (text){
                  if (text == "Ready to Print") {
                      _this.selected_printer.send(_this.format_start + _this.format_content + _this.format_end, function(){
                          _this.common.successTip("Print Outer Success");
                            if(_this.updateForm.printMode == "4" && _this.isPrintMode4Flag){
                                _this.isPrintMode4Flag=false;
                                _this.printOuter();
                            }
                          }, function(){
                          _this.common.errorTip("Print Outer Error");
                      });
                  }
                  else {
                      _this.common.errorTip("errorOuter");
                  }
              });
          },
          backPrint(){
              this.dialogUpdate = false;
              this.$refs['updateForm'].resetFields();
          },
          startTime(val){
              this.formInline.startCreateTime=val;
          },
          endTime(val){
              this.formInline.endCreateTime=val;
          },
          //分页
          handleSizeChange(val) {
              // console.log(`每页 ${val} 条`);
              this.pageSize = val;
              this.query();
          },
          //点击页码分页查询点击事件
          handleCurrentChange(val) {
              // console.log(`当前页: ${val}`);
              this.pageIndex = val;
              this.query();
          },
          //文件列表移除文件时的钩子
          handleRemove(file, fileList) {
              console.log(file, fileList);
          },
          handlePreview(file) {
              console.log(file);
          }
      }

}
</script>
